<?PHP
require_once("table.class.php");
require_once("inc/strings.en.php");

function claxml_header()
{
	echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
	echo "\n";
}

function claxml_error($ERRCODE)
{
	global $_STRINGS;
	$msg = $_STRINGS[$ERRCODE];

	// See if we have optional args. They are offendors.
	if(func_num_args() >= 2){
		$args = func_get_args();
		unset($args[0]);
		$list = implode(", ", $args);

		if(strlen($list) > 0)
			$msg = "'$msg' caused by '$list'";
	}

	echo "<error>\n\t<item>\n\t\t<msg>{$msg}</msg>\n\t\t<code>{$ERRCODE}</code>\n\t</item>\n</error>";
}

function claxml_result2list($item, $result)
{
	echo "<list>\n";
	foreach($result as $row)
	{
		echo "\t<$item>\n";
		$keys = array_keys($row);
		foreach($keys as $key)
		{
			$data = htmlspecialchars($row[$key]);
			echo "\t\t<$key>$data</$key>\n";
		}

		echo "\t</$item>\n";
	
	}
	echo "</list>";
}

function claxml_response($values) {
	$keys = array_keys( $values );
	echo "<response>\n";
	echo "\t<values>\n";
	foreach($keys as $name) {
		$value = htmlspecialchars($values[$name]);
		echo "\t\t<$name>$value</$name>\n";
	}
	echo "\t</values>\n";
	echo "</response>";
}
